package TicketSell;

public class TicketStation extends Thread{
    private static int MaxTickets;
    public TicketStation(int MaxTicketNum){
        MaxTickets = MaxTicketNum;
    }
    @Override
    public void run() {
        while (MaxTickets>0)
            sellTicket();
    }
    private synchronized boolean sellTicket(){
        System.out.println(Thread.currentThread().getName() + "卖出1张票, 剩余：" + --MaxTickets + "张票...");
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return MaxTickets==0;
    }

}
